var _timer = 30000;
var _split = 1;
var _id = 0;

var g_numcolor = [0,1,1,2,2,3,3,1,1,2,2,3,1,1,2,2,3,3,1,1,2,3,3,1,1,2,2,3,3,1,1,2,3,3,1,1,2,2,3,3,1,2,2,3,3,1,1,2,2,3];
var colors = ["","red", "blue", "green"];
var XH = null;
var XH1= null;
if (window.XMLHttpRequest)
{// code for all new browsers
    XH = new XMLHttpRequest();
    XH1 = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{// code for IE5 and IE6
  XH = new ActiveXObject("Microsoft.XMLHTTP");
  XH1 = new ActiveXObject("Microsoft.XMLHTTP");
} else 
  alert("Your browser does not support XMLHTTP.");

var timer_id;
var chkbutmod = false;
var mchk21 = [0,0,0,0,0,0,0,0,0,0,0,0,0];
var mchk22 = [0,0,0,0,0,0,0,0,0,0,0];
var mchk34 = [0,0,0,0,0];
var mchk35 = [0,0,0];
var b213_num = "";
var b223_num = "";
var b343_num = "";
var b353_num = "";

function getcontent()
{
    XH.open("POST", "op.php?op=xml&fp=bnow5&id="+_id+"&split="+_split,false); 
    try{XH.send("");return XH.responseText; }catch(E){}
}

function timer()
{
	window.status = _status;
	var i;
	var str = getcontent();
	if (str=="") { alert("Error 1"); }
	if (str=="-1") { location.reload(); }

	var a = str.split("\n");
	show_rate21(a[0]);
	show_rate22(a[1]);
	show_titleAmu(a[2]);
	window.status = "";

	// timer_id = setTimeout("timer()", _timer);
}

function show_rate21(str)
{
	var a0 = str.split(",");
	var win = a0[0];
	for (i=1; i<13; i++) {
		a00 = a0[i].split("@");
		rate = a00[0];
		count = a00[1]-0;
		amount = a00[2]-0;
		chktime = a00[4]-0;
		document.all["num21_"+i].innerHTML = _name21[i];
		document.all["rate21_"+i].innerHTML = rate;
		mchk21[i] = Math.floor(amount);
		if (count > 0) {
			document.all["amount21_"+i].innerHTML = "<a href=op.php?op=agent&fp=betlist&dt1="+_open+"&dt2="+_open+"&bettype=1006&numbers="+i+">"+Math.floor(amount)+"</a>";
			if (chktime == 0 && amount > 0) {
				document.all["chg21_"+i].innerHTML = "<input type=checkbox id=rrr21_"+d2(i)+" onclick=\"quickrrr(21, "+i+")\">";
			} else {
				document.all["chg21_"+i].innerHTML = "<input disabled type=checkbox id=rrr21_"+d2(i)+">";
			}
		} else {
			document.all["amount21_"+i].innerHTML = Math.floor(amount);
			document.all["chg21_"+i].innerHTML = "<input disabled type=checkbox id=rrr21_"+d2(i)+">";
		}
		win1 = Math.floor(win - a00[3]);
		document.all["win21_"+i].innerHTML = win1;
		document.all["win21_"+i].className = (win1 < 0 ? "lost" : "win");
	}
}

function gen_rate21()
{
	ret = "<table width=100% cellpadding=2 cellspacing=1 border=0 class=table0>"
		+"<tr id=rate0hd class=td0 align=center>";
	for (i=0; i<2; i++) ret += _tb21head;
	ret += "</tr>";
	
	for (j=0; j<6; j++) {
		ret += "<tr class=td2 align=right>";
		for (i=1; i<3; i++) {
			k = i + j*2;
			ret += "<td id=num21_"+k+" class=td6 align=center></td><td nowrap id=amount21_"+k+"></td><td nowrap id=win21_"+k+"></td><td id=rate21_"+k+" class=rate></td><td align=center id=chg21_"+k+"></td>";
		}
		ret += "</tr>";
	}
	ret += "</table>";
	document.all.div21.innerHTML = ret;
}

function show_rate22(str)
{
	var a0 = str.split(",");
	var win = a0[0];
	for (i=1; i<11; i++) {
		a00 = a0[i].split("@");
		rate = a00[0];
		count = a00[1]-0;
		amount = a00[2]-0;
		chktime = a00[4]-0;
		document.all["num22_"+i].innerHTML = _name22[i];
		document.all["rate22_"+i].innerHTML = rate;
		mchk22[i] = Math.floor(amount);
		if (count > 0) {
			document.all["amount22_"+i].innerHTML = "<a href=op.php?op=agent&fp=betlist&dt1="+_open+"&dt2="+_open+"&bettype=1007&numbers="+i+">"+Math.floor(amount)+"</a>";
			if (chktime == 0 && amount > 0) {
				document.all["chg22_"+i].innerHTML = "<input type=checkbox id=rrr22_"+d2(i)+" onclick=\"quickrrr(22, "+i+")\">";
			} else {
				document.all["chg22_"+i].innerHTML = "<input disabled type=checkbox id=rrr22_"+d2(i)+">";
			}
		} else {
			document.all["amount22_"+i].innerHTML = Math.floor(amount);
			document.all["chg22_"+i].innerHTML = "<input disabled type=checkbox id=rrr22_"+d2(i)+">";
		}
		win1 = Math.floor(win - a00[3]);
		document.all["win22_"+i].innerHTML = win1;
		document.all["win22_"+i].className = (win1 < 0 ? "lost" : "win");
	}
}

function gen_rate22()
{
	ret = "<table width=100% cellpadding=2 cellspacing=1 border=0 class=table0>"
		+"<tr id=rate0hd class=td0 align=center>";
	for (i=0; i<2; i++) ret += _tb22head;
	ret += "</tr>";
	
	for (j=0; j<5; j++) {
		ret += "<tr class=td2 align=right>";
		for (i=1; i<3; i++) {
			k = i + j*2;
			ret += "<td id=num22_"+k+" class=td6 align=center></td><td nowrap id=amount22_"+k+"></td><td nowrap id=win22_"+k+"></td><td id=rate22_"+k+" class=rate></td><td align=center id=chg22_"+k+"></td>";
		}
		ret += "</tr>";
	}
	ret += "</table>";
	document.all.div22.innerHTML = ret;
}

function show_titleAmu(str)
{
	var a0 = str.split(",");
	var i = 0;
	var l = a0.length;
	var amu = 0;
	var clr = '';
	var oObj = '';
	for (i=0; i<l; i++) {
		a00 = a0[i].split("@");
		amu = a00[0];
		if(a00[1] > 0){ clr = '#ffff99';  }else{ clr = 'transparent';  }
    oObj = document.getElementById("menuAmu"+i);
    oObj.innerHTML = amu;
    oObj.style.backgroundColor = clr;
	}
}
function quickrrr(c, i)
{
	if (document.all["rrr"+c+"_"+d2(i)].checked) {
		if (!chkbutmod) {
			chkbutmod = true;
		}
		if (timer_id) clearTimeout(timer_id);
	}
}

function protect_b1()
{
	var bw = 262;
	var sr = 0;
	var hi =104;
	var count = 0;
	var _bet = new Array();
	var _num = new Array();
	var _chk = new Array();
	var _rate = new Array();
	var _amount = new Array();
	b213_num = document.all.b213.value-0;
	if (b213_num > 0) {
		for (i=1; i<13; i++) {
			if (document.all["rrr21_"+d2(i)].checked) {
				_bet[count] = 21;
				_num[count] = i;
				_rate[count] = document.all["rate21_"+i].innerHTML;
				_chk[count] = mchk21[i];
				_amount[count] = b213_num;
				count++;
			}
		}
		if (count > 0) {
			hi += (count * 26);
			if (count > 24) {
				sr = 1;
				bw = 280;
				hi = 794;
			}
			var X = screen.width - bw - 10;
			var Y = 0;
			// var newwin = window.open("op.php?op=agent&fp=protsaves&btype="+_bet+"&num="+_num+"&rate="+_rate+"&amount="+_amount+"&chk="+_chk,'WinProtPop','menubar=no,status=yes,scrollbars='+sr+',toolbar=no,top='+Y+',left='+X+',width='+bw+',height='+hi);
			 var newwin = myCreateDiv("op.php?op=agent&fp=protsaves&btype="+_bet+"&num="+_num+"&rate="+_rate+"&amount="+_amount+"&chk="+_chk);
      //setTimeout("isPopOpen(newwin)",1500);
		}
	}
	b213_num = "";
	document.all.b213.value = b213_num;
	if (chkbutmod) {
		chkbutmod = false;
		timer();
	}
}

function protect_b2()
{
	var bw = 262;
	var sr = 0;
	var hi =104;
	var count = 0;
	var _bet = new Array();
	var _num = new Array();
	var _chk = new Array();
	var _rate = new Array();
	var _amount = new Array();
	b223_num = document.all.b223.value-0;
	if (b223_num > 0) {
		for (i=1; i<11; i++) {
			if (document.all["rrr22_"+d2(i)].checked) {
				_bet[count] = 22;
				_num[count] = i;
				_rate[count] = document.all["rate22_"+i].innerHTML;
				_chk[count] =  mchk22[i];;
				_amount[count] = b223_num;
				count++;
			}
		}
		if (count > 0) {
			hi += (count * 26);
			if (count > 24) {
				sr = 1;
				bw = 280;
				hi = 794;
			}
			var X = screen.width - bw - 10;
			var Y = 0;
			// var newwin = window.open("op.php?op=agent&fp=protsaves&btype="+_bet+"&num="+_num+"&rate="+_rate+"&amount="+_amount+"&chk="+_chk,'WinProtPop','menubar=no,status=yes,scrollbars='+sr+',toolbar=no,top='+Y+',left='+X+',width='+bw+',height='+hi);
			var newwin = myCreateDiv("op.php?op=agent&fp=protsaves&btype="+_bet+"&num="+_num+"&rate="+_rate+"&amount="+_amount+"&chk="+_chk);
      //setTimeout("isPopOpen(newwin)",1500);
		}
	}
	b223_num = "";
	document.all.b223.value = b223_num;
	if (chkbutmod) {
		chkbutmod = false;
		timer();
	}
}

function protect_b3()
{
	var bw = 262;
	var sr = 0;
	var hi =104;
	var count = 0;
	var _bet = new Array();
	var _num = new Array();
	var _chk = new Array();
	var _rate = new Array();
	var _amount = new Array();
	b343_num = document.all.b343.value-0;
	if (b343_num > 0) {
		for (i=1; i<5; i++) {
			if (document.all["rrr34_"+d2(i)].checked) {
				_bet[count] = 34;
				_num[count] = i+3;
				_rate[count] = document.all["rate34_"+i].innerHTML;
				_chk[count] = mchk34[i];
				_amount[count] = b343_num;
				count++;
			}
		}
		if (count > 0) {
			hi += (count * 26);
			if (count > 24) {
				sr = 1;
				bw = 280;
				hi = 794;
			}
			var X = screen.width - bw - 10;
			var Y = 0;
			// var newwin = window.open("op.php?op=agent&fp=protsaves&btype="+_bet+"&num="+_num+"&rate="+_rate+"&amount="+_amount+"&chk="+_chk,'WinProtPop','menubar=no,status=yes,scrollbars='+sr+',toolbar=no,top='+Y+',left='+X+',width='+bw+',height='+hi);
			var newwin = myCreateDiv("op.php?op=agent&fp=protsaves&btype="+_bet+"&num="+_num+"&rate="+_rate+"&amount="+_amount+"&chk="+_chk);
      //setTimeout("isPopOpen(newwin)",1500);
		}
	}
	b343_num = "";
	document.all.b343.value = b343_num;
	if (chkbutmod) {
		chkbutmod = false;
		timer();
	}
}

function protect_b4()
{
	var bw = 262;
	var sr = 0;
	var hi =104;
	var count = 0;
	var _bet = new Array();
	var _num = new Array();
	var _chk = new Array();
	var _rate = new Array();
	var _amount = new Array();
	b353_num = document.all.b353.value-0;
	if (b353_num > 0) {
		for (i=1; i<3; i++) {
			if (document.all["rrr35_"+d2(i)].checked) {
				_bet[count] = 35;
				_num[count] = i;
				_rate[count] = document.all["rate35_"+i].innerHTML;
				_chk[count] = mchk35[i];
				_amount[count] = b353_num;
				count++;
			}
		}
		if (count > 0) {
			hi += (count * 26);
			if (count > 24) {
				sr = 1;
				bw = 280;
				hi = 794;
			}
			var X = screen.width - bw - 10;
			var Y = 0;
			// var newwin = window.open("op.php?op=agent&fp=protsaves&btype="+_bet+"&num="+_num+"&rate="+_rate+"&amount="+_amount+"&chk="+_chk,'WinProtPop','menubar=no,status=yes,scrollbars='+sr+',toolbar=no,top='+Y+',left='+X+',width='+bw+',height='+hi);
			var newwin = myCreateDiv("op.php?op=agent&fp=protsaves&btype="+_bet+"&num="+_num+"&rate="+_rate+"&amount="+_amount+"&chk="+_chk);
      //setTimeout("isPopOpen(newwin)",1500);
		}
	}
	b353_num = "";
	document.all.b353.value = b353_num;
	if (chkbutmod) {
		chkbutmod = false;
		timer();
	}
}

function prot_list()
{
	var X = (screen.width-470)/2;
	var Y = (screen.Height-424)/2;
	// var newwin = window.open("op.php?op=agent&fp=protlists&bmd=3",'WinPopList','menubar=no,status=yes,scrollbars=no,toolbar=no,top='+Y+',left='+X+',width=540,height=412');
	var newwin = myCreateDiv("op.php?op=agent&fp=protlists&bmd=3");
  //setTimeout("isPopOpen(newwin)",1500);
}
function myCreateDiv(sSrc){
    var shadow = document.createElement("div");
    shadow.setAttribute("id","speShadow2");
    shadow.style.zIndex="100";

    var box = document.createElement("div");
    box.setAttribute("id","speBox2");
    box.style.zIndex="999";
    
    var closeBar = document.createElement("div");
    closeBar.setAttribute("id","closeBar");
    
    var iptClose = document.createElement("input");
    iptClose.setAttribute("type","button");
    iptClose.setAttribute("value"," X ");
    iptClose.setAttribute("className","c4");
    iptClose.onclick = function() {myCloseMyDiv(0);};
    
    closeBar.appendChild(iptClose);
    box.appendChild(closeBar);
    
    var myIframe = document.createElement("iframe");
    myIframe.setAttribute("id","myIfram_target");
    myIframe.setAttribute("name","myIfram_target");
    myIframe.style.width = "100%";
    myIframe.style.height = "100%";
    myIframe.src = sSrc;
    box.appendChild(myIframe);
    
    document.body.appendChild(shadow);
    document.body.appendChild(box);    
}

function myCloseMyDiv(oReload){
    var shadow=document.getElementById("speShadow2");
    if(shadow != undefined){
      var box=document.getElementById("speBox2");
      document.body.removeChild(box);
      document.body.removeChild(shadow);
      if(oReload) window.location.reload();
    }
    
}

function w(s) {
	document.write(s);
}

function winonload()
{
	gen_rate21();
	gen_rate22();
	b213_num = document.all.b213.value-0;
	b223_num = document.all.b223.value-0;
	chkbutmod = false;
	timer();
}

window.onload = winonload;